﻿@model BusinessLayer.VDataEntities.VReportBasicInfo
@{
    ViewBag.Title = @Model.Name;
    Layout = "~/Views/Shared/Layout.Mobile.cshtml";
}
<style>
    .content {
        width: 100%;
    }
</style>
<div class="page-group">
    <div class="page page-current">
        <div class="content">
            <div class="headClass">用药信息</div>
            <div class="list-block" style="width:98%;margin-bottom:1px;margin-top:0px">
                <ul id="tab1ul"></ul>
            </div>
            @if (Model.Status == 0 || Model.Status == 1)
            {
                <div style="margin-top:10px;margin-bottom:10px">
                    <img style="height:14px;margin:10px;float:left;margin-right:5px" src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/Group.png")" />
                    <a onclick="javascript:CreateReport(false)" class="prompt-ok-cancel" style="font-size:20px">添加用药信息</a>
                </div>
            }
            <div class="headClass">调查信息</div>
            <div class="list-block" style="width:98%;margin-bottom:1px;margin-top:0px">
                <ul id="tab2ul"></ul>
            </div>
            @if (Model.Status == 0 || Model.Status == 1)
            {
                <div style="margin-top:10px">
                    <img style="height:14px;margin:10px;float:left;margin-right:5px" src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/Group.png")" />
                    <a onclick="javascript:CreateReport(true)" class="confirm-ok-cancel" style="font-size:20px">添加调查信息</a>
                </div>
            }
            <a href="#" style="width:80%;margin:20px auto 30px auto" class="button button-big button-fill button-success" onclick="location.href='@TrialManagementTool.Helper.UrlHelper.alterContent("TrialMobile/ReportManagement?id="+@Model.TrialSiteID)'">返回试验点详情</a>
        </div>
        <div style="position:absolute;right:0;top:100px;z-index:2001">
            <a class="filterArea" onclick="loadPage()"> <img src="@TrialManagementTool.Helper.UrlHelper.alterContent("Images/fangan.png")" class="fangan" />  </a>
        </div>
    </div>
</div>
<div class="page" id="purpose">
    <header class="bar bar-nav">
        <a class="button button-link button-nav pull-left back">
            <span class="icon icon-left"></span>
            返回
        </a>
        <h1 class='title'>示例方案</h1>
    </header>
    <div class="content" style="width:90%">

        @{var data = new ViewDataDictionary();

        data.Add("TrialGuideID", @Model.TrialGuideID);
        Html.RenderPartial("Purpose", null, data); }
    </div>
</div>

<script>
    function CreateElement(target, name, id) {
        var content = '<li class="item-content" ><div class="item-media"><i class="icon icon-f7"></i></div><div class="item-inner"  onclick=location.href=\'' + fixUrl("TrialMobile/addnewreport?reportid=" + id) + '\'><div class="item-title">' + name +
            '</div><div class="item-after"><span class="icon icon-right"></span></div></div></li>'
        $("#" + target).append(content);
    }

    function CreateReport(isObserve) {
        if (alreadyhaveyongyao == true && isObserve == false) {
            $.modal({
                text: '是否自动导入上一次用药信息?',
                buttons: [
                  {
                      text: '否',
                      onClick: function () {
                          ProcessCreateImport(isObserve, false)
                      }
                  },
                  {
                      text: '是',
                      onClick: function () {
                          ProcessCreateImport(isObserve, true)
                      }
                  },
                ]
            })
        } else {
            ProcessCreateImport(isObserve, false)
        }
    }

    function ProcessCreateImport(isObserve, isImport) {
        $.ajax({
            beforeload: $.showPreloader('正在创建...'),
            type: "post",
            url: fixUrl("api/Trial/CreateNewReport"),
            data: { ID: '@Model.ID', IsObserveInfo: isObserve, AutoImport: isImport },
            success: function (data) {
                location.href = fixUrl("trialMobile/addnewreport?reportid=" + data);
            }, error: function (data) {
                $.hidePreloader();
                if (data.statuscode == "401") {
                    $.alert('登录超时');
                } else {
                    $.hidePreloader();
                    $.alert('创建失败');
                }
            }
        })
    }
    var alreadyhaveyongyao = false;
    $.ajax({
        type: "get",
        url: fixUrl("api/Trial/GetProcessInfoByProcessID"),
        data: { ID: '@Model.ID' },

        success: function (data) {
            $.each(data, function (index, value) {
                if (value.IsObserveInfo == true) {
                    CreateElement("tab2ul", value.ReportName, value.ID)
                } else {
                    alreadyhaveyongyao = true;
                    CreateElement("tab1ul", value.ReportName, value.ID)
                }
            })
        }
    })
    function loadPage() {
        $.router.load("#purpose");
        init();
    }
</script>